package com.code2roc.jarmanage.filter;

import com.code2roc.jarmanage.model.Result;
import com.code2roc.jarmanage.util.CommonUtil;
import com.code2roc.jarmanage.util.EnviromentUtil;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class PHPEnvCheckFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        if (EnviromentUtil.checkPHPEnvINstall()) {
            filterChain.doFilter(servletRequest, servletResponse);
        } else {
            response.sendRedirect(CommonUtil.getRooptPath(request) + "pages/error/601.html");
        }
    }

    @Override
    public void destroy() {

    }
}
